package com.zhsj.OkeHomeConsumption.ui.activity.bussiness;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.empty.BusinessBean;
import com.zhsj.OkeHomeConsumption.empty.CitypantnerRemake;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.network.HttpClient;
import com.zhsj.OkeHomeConsumption.network.JsonResponseHandler;
import com.zhsj.OkeHomeConsumption.other.URLEntity;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.MinewalletActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.TimeOutHandler;
import com.zhsj.OkeHomeConsumption.utils.JsonUtils;
import com.zhsj.OkeHomeConsumption.utils.LogUtils;
import com.zhsj.OkeHomeConsumption.utils.SignUtil;

import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 商家--我的钱包
 */
public class BusinessWalletActivity extends MyActivity {


    @BindView(R.id.yue_text)
    TextView yueText;
    @BindView(R.id.zongshouru_text)
    TextView zongshouruText;
    @BindView(R.id.zongshouru)
    LinearLayout zongshouru;
    @BindView(R.id.yitixian_text)
    TextView yitixianText;
    @BindView(R.id.yitixian)
    LinearLayout yitixian;
    @BindView(R.id.yujishouru_text)
    TextView yujishouruText;
    @BindView(R.id.yujishouru)
    LinearLayout yujishouru;
    @BindView(R.id.lin)
    LinearLayout lin;

    private LinearLayout jifenlin;

    private FormalUserInfo userInfo;
    private CitypantnerRemake remake;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_wallet;
    }

    @Override
    protected int getTitleId() {
        return R.id.title;
    }

    protected void initView() {
        userInfo = Hawk.get(Constants.SHARED_PERFERENCE_USERINFO);

    }

    @Override
    protected void initData() {
        IsWalletUser(userInfo.getId());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    //查询钱包信息
    public void IsWalletUser(int id) {
        // post传参使用的HashMap
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        // 生成sign值所使用的HashMap
        HashMap<String, String> mSendCodeHashMap = new HashMap<String, String>();
//        mSendCodeHashMap.put("token", Constants.TOKEN);
        mSendCodeHashMap.put("v", Constants.APPVERSION);
        mSendCodeHashMap.put("t", Constants.TIME);
        mSendCodeHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mSendCodeHashMap.put("platform", Constants.PLAFORM);
        mSendCodeHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mSendCodeHashMap.put("client", Constants.CLIENT);
        paramMaps.put("userId",String.valueOf(id));
        mSendCodeHashMap.put("userId", String.valueOf(id));
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mSendCodeHashMap);
        LogUtils.e("mSendCodeHashMap", SignUtil.getInstance().getSign(mSendCodeHashMap));
        HttpClient.get(OkeHomeConsumptionApi.ELVDOU_INCOMERECORDDE, paramMaps, new JsonResponseHandler() {

            @Override
            public void onSuccess(int statusCode, String content) {
                // TODO Auto-generated method stub
                super.onSuccess(statusCode, content);
                try {
                    JSONTokener jsonT = new JSONTokener(content);
                    JSONObject jsonOBJ = (JSONObject) jsonT.nextValue();
                    String code = jsonOBJ.optString("code");
                    String message = jsonOBJ.optString("message");
                    if (code.equals("N000000")) {
                        JSONObject jsonobj = jsonOBJ.optJSONObject("data");
                        // 数据对接正常
                        BusinessBean remake = JsonUtils.object(jsonobj.toString(), BusinessBean.class);
                        yueText.setText(remake.getLianLianBalance()+"");
                        zongshouruText.setText(remake.getTotalIncome()+ "");
                        yitixianText.setText(remake.getExtractCash()+ "");
                        yujishouruText.setText(remake.getBalance()+ "");
                    } else if (code.equals(Constants.STATUSTOKENERROR)) {
                        if (!message.equals("null")) {
                        }
                    } else {
                        if (!message.equals("null")) {
                        }
                    }
                } catch (Exception ex) {
                    LogUtils.e("DresserPartnerRegisterPost", "失败 ");
                }
            }

            @Override

            public void onFailure(Throwable e) {
                // TODO Auto-generated method stub
                super.onFailure(e);
                LogUtils.e("onFailure", "" + e.toString());
            }
        });
    }

    @OnClick({R.id.zongshouru, R.id.yitixian, R.id.yujishouru, R.id.lin})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.zongshouru:
                //总收入
                Intent intent7 = new Intent(getActivity(), BussinessLookpayeeActivity.class);
                intent7.putExtra("flag", 7);//商家 总收入
                startActivity(intent7);
                break;
            case R.id.yitixian:
                Intent intent9 = new Intent(getActivity(), BussinessLookpayeeActivity.class);
                intent9.putExtra("flag", 9);//商家 已提现
                startActivity(intent9);
                break;
            case R.id.yujishouru:
                Intent intent8 = new Intent(getActivity(), BussinessLookpayeeActivity.class);
                intent8.putExtra("flag", 8);//商家 预计收入
                startActivity(intent8);
                break;
            case R.id.lin:
                startActivity(MinewalletActivity.class);
                break;
        }
    }
}
